<!DOCTYPE html>
<html>
<head>
    

    

    



    <meta charset="utf-8">
    
    
    
    
    <title>python|机器学习之随机森林算法 | 一只咸鱼 | 努力学习最新姿势！！！</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    
    <meta name="theme-color" content="#3F51B5">
    
    
    <meta name="keywords" content="Python">
    <meta name="description" content="前言随机森林Python版本有很可以调用的库，使用随机森林非常方便，主要用到以下的库 sklearnScikit learn 也简称 sklearn, 是机器学习领域当中最知名的 python 模块之一.Sklearn 包含了很多种机器学习的方式: Classification  分类 Regression  回归 Clustering  非监督分类 Dimensionalityreduction">
<meta property="og:type" content="article">
<meta property="og:title" content="python|机器学习之随机森林算法">
<meta property="og:url" content="http://yoursite.com/2020/04/06/python-%E6%9C%BA%E5%99%A8%E5%AD%A6%E4%B9%A0%E4%B9%8B%E9%9A%8F%E6%9C%BA%E6%A3%AE%E6%9E%97%E7%AE%97%E6%B3%95/index.html">
<meta property="og:site_name" content="一只咸鱼">
<meta property="og:description" content="前言随机森林Python版本有很可以调用的库，使用随机森林非常方便，主要用到以下的库 sklearnScikit learn 也简称 sklearn, 是机器学习领域当中最知名的 python 模块之一.Sklearn 包含了很多种机器学习的方式: Classification  分类 Regression  回归 Clustering  非监督分类 Dimensionalityreduction">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://img-blog.csdn.net/20170116134958784?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvY3htc2Ni/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/80/gravity/SouthEast">
<meta property="og:image" content="https://img-blog.csdnimg.cn/20190424175513353.png">
<meta property="article:published_time" content="2020-04-06T08:41:00.000Z">
<meta property="article:modified_time" content="2020-04-07T06:38:59.417Z">
<meta property="article:author" content="Mr.Zhang">
<meta property="article:tag" content="Python">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://img-blog.csdn.net/20170116134958784?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvY3htc2Ni/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/80/gravity/SouthEast">
    
        <link rel="alternate" type="application/atom+xml" title="一只咸鱼" href="/atom.xml">
    
    <link rel="shortcut icon" href="/favicon.ico">
    <link rel="stylesheet" href="//unpkg.com/hexo-theme-material-indigo@latest/css/style.css">
    <script>window.lazyScripts=[]</script>

    <!-- custom head -->
    

<meta name="generator" content="Hexo 4.2.0"></head>

<body>
    <div id="loading" class="active"></div>

    <aside id="menu" class="hide" >
  <div class="inner flex-row-vertical">
    <a href="javascript:;" class="header-icon waves-effect waves-circle waves-light" id="menu-off">
        <i class="icon icon-lg icon-close"></i>
    </a>
    <div class="brand-wrap" style="background-image:url(/img/brand.jpg)">
      <div class="brand">
        <a href="/" class="avatar waves-effect waves-circle waves-light">
          <img src="/img/avatar.jpg">
        </a>
        <hgroup class="introduce">
          <h5 class="nickname">Mr.Zhang</h5>
          <a href="mailto:zhangticcc@163.com" title="zhangticcc@163.com" class="mail">zhangticcc@163.com</a>
        </hgroup>
      </div>
    </div>
    <div class="scroll-wrap flex-col">
      <ul class="nav">
        
            <li class="waves-block waves-effect">
              <a href="/"  >
                <i class="icon icon-lg icon-home"></i>
                首页
              </a>
            </li>
        
            <li class="waves-block waves-effect">
              <a href="/archives"  >
                <i class="icon icon-lg icon-archives"></i>
                时间轴
              </a>
            </li>
        
            <li class="waves-block waves-effect">
              <a href="/tags"  >
                <i class="icon icon-lg icon-tags"></i>
                标签
              </a>
            </li>
        
            <li class="waves-block waves-effect">
              <a href="/categories"  >
                <i class="icon icon-lg icon-th-list"></i>
                分类
              </a>
            </li>
        
            <li class="waves-block waves-effect">
              <a href="https://weibo.com/u/5392412243" target="_blank" >
                <i class="icon icon-lg icon-weibo"></i>
                微博
              </a>
            </li>
        
            <li class="waves-block waves-effect">
              <a href="https://github.com/zhangti0708" target="_blank" >
                <i class="icon icon-lg icon-github"></i>
                开源地址
              </a>
            </li>
        
            <li class="waves-block waves-effect">
              <a href="https://blog.csdn.net/weixin_40902527" target="_blank" >
                <i class="icon icon-lg icon-rss"></i>
                技术博客
              </a>
            </li>
        
            <li class="waves-block waves-effect">
              <a href="http://zhangticcc.gitee.io/webgis/" target="_blank" >
                <i class="icon icon-lg icon-globe"></i>
                GIS案例
              </a>
            </li>
        
            <li class="waves-block waves-effect">
              <a href="https://mp.weixin.qq.com/s/p4TOhKcr4RZkZWzuMYyBEQ" target="_blank" >
                <i class="icon icon-lg icon-weixin"></i>
                微信订阅号
              </a>
            </li>
        
      </ul>
    </div>
  </div>
</aside>

    <main id="main">
        <header class="top-header" id="header">
    <div class="flex-row">
        <a href="javascript:;" class="header-icon waves-effect waves-circle waves-light on" id="menu-toggle">
          <i class="icon icon-lg icon-navicon"></i>
        </a>
        <div class="flex-col header-title ellipsis">python|机器学习之随机森林算法</div>
        
        <div class="search-wrap" id="search-wrap">
            <a href="javascript:;" class="header-icon waves-effect waves-circle waves-light" id="back">
                <i class="icon icon-lg icon-chevron-left"></i>
            </a>
            <input type="text" id="key" class="search-input" autocomplete="off" placeholder="输入感兴趣的关键字">
            <a href="javascript:;" class="header-icon waves-effect waves-circle waves-light" id="search">
                <i class="icon icon-lg icon-search"></i>
            </a>
        </div>
        
        
        <a href="javascript:;" class="header-icon waves-effect waves-circle waves-light" id="menuShare">
            <i class="icon icon-lg icon-share-alt"></i>
        </a>
        
    </div>
</header>
<header class="content-header post-header">

    <div class="container fade-scale">
        <h1 class="title">python|机器学习之随机森林算法</h1>
        <h5 class="subtitle">
            
                <time datetime="2020-04-06T08:41:00.000Z" itemprop="datePublished" class="page-time">
  2020-04-06
</time>


	<ul class="article-category-list"><li class="article-category-list-item"><a class="article-category-list-link" href="/categories/%E6%9C%BA%E5%99%A8%E5%AD%A6%E4%B9%A0/">机器学习</a></li></ul>

            
        </h5>
    </div>

    


</header>


<div class="container body-wrap">
    
    <aside class="post-widget">
        <nav class="post-toc-wrap post-toc-shrink" id="post-toc">
            <h4>TOC</h4>
            <ol class="post-toc"><li class="post-toc-item post-toc-level-3"><a class="post-toc-link" href="#前言"><span class="post-toc-number">1.</span> <span class="post-toc-text">前言</span></a></li><li class="post-toc-item post-toc-level-3"><a class="post-toc-link" href="#sklearn"><span class="post-toc-number">2.</span> <span class="post-toc-text">sklearn</span></a></li><li class="post-toc-item post-toc-level-3"><a class="post-toc-link" href="#numpy"><span class="post-toc-number">3.</span> <span class="post-toc-text">numpy</span></a></li><li class="post-toc-item post-toc-level-3"><a class="post-toc-link" href="#pandas"><span class="post-toc-number">4.</span> <span class="post-toc-text">pandas</span></a></li><li class="post-toc-item post-toc-level-3"><a class="post-toc-link" href="#RandomForestRegressor"><span class="post-toc-number">5.</span> <span class="post-toc-text">RandomForestRegressor</span></a></li><li class="post-toc-item post-toc-level-3"><a class="post-toc-link" href="#自定义模型"><span class="post-toc-number">6.</span> <span class="post-toc-text">自定义模型</span></a></li></ol>
        </nav>
    </aside>


<article id="post-python-机器学习之随机森林算法"
  class="post-article article-type-post fade" itemprop="blogPost">

    <div class="post-card">
        <h1 class="post-card-title">python|机器学习之随机森林算法</h1>
        <div class="post-meta">
            <time class="post-time" title="2020-04-06 16:41:00" datetime="2020-04-06T08:41:00.000Z"  itemprop="datePublished">2020-04-06</time>

            
	<ul class="article-category-list"><li class="article-category-list-item"><a class="article-category-list-link" href="/categories/%E6%9C%BA%E5%99%A8%E5%AD%A6%E4%B9%A0/">机器学习</a></li></ul>



            
<span id="busuanzi_container_page_pv" title="文章总阅读量" style='display:none'>
    <i class="icon icon-eye icon-pr"></i><span id="busuanzi_value_page_pv"></span>
</span>


        </div>
        <div class="post-content" id="post-content" itemprop="postContent">
            <h3 id="前言"><a href="#前言" class="headerlink" title="前言"></a>前言</h3><p>随机森林Python版本有很可以调用的库，使用随机森林非常方便，主要用到以下的库</p>
<h3 id="sklearn"><a href="#sklearn" class="headerlink" title="sklearn"></a>sklearn</h3><p>Scikit learn 也简称 sklearn, 是机器学习领域当中最知名的 python 模块之一.<br>Sklearn 包含了很多种机器学习的方式:</p>
<p><code>Classification</code>  分类</p>
<p><code>Regression</code>  回归</p>
<p><code>Clustering</code>  非监督分类</p>
<p><code>Dimensionalityreduction</code>  数据降维</p>
<p><code>Model Selection</code>  模型选择</p>
<p><code>Preprocessing</code>  数据预处理</p>
<p>Sklearn快速入门：<code>https://www.jianshu.com/p/cd5a929bec33</code></p>
<h3 id="numpy"><a href="#numpy" class="headerlink" title="numpy"></a>numpy</h3><p>numpy（Numerical Python）提供了python对多维数组对象的支持：ndarray，具有矢量运算能力，快速、节省空间。numpy支持高级大量的维度数组与矩阵运算，此外也针对数组运算提供大量的数学函数库。</p>
<img src="https://img-blog.csdn.net/20170116134958784?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvY3htc2Ni/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/80/gravity/SouthEast"  title="">

<p>numpy快速入门:<code>https://blog.csdn.net/cxmscb/article/details/54583415</code></p>
<h3 id="pandas"><a href="#pandas" class="headerlink" title="pandas"></a>pandas</h3><p>pandas 是基于 Numpy 构建的含有更高级数据结构和工具的数据分析包 类似于 Numpy 的核心是 ndarray，pandas 也是围绕着 Series 和 DataFrame 两个核心数据结构展开的 。Series 和 DataFrame 分别对应于一维的序列和二维的表结构。</p>
<p>pandas使用教程：<code>https://blog.csdn.net/qq_38251616/article/details/79775789</code></p>
<h3 id="RandomForestRegressor"><a href="#RandomForestRegressor" class="headerlink" title="RandomForestRegressor"></a>RandomForestRegressor</h3><ol>
<li>导入模块，创建模型</li>
</ol>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">import matplotlib.pyplot as plt #可视化图形库</span><br><span class="line">import numpy as np    #numpy多维数值操作库</span><br><span class="line">import pandas as pd    #pandas数据分析库</span><br><span class="line">from sklearn import datasets, cross_validation, ensemble #sklearn机器学习库</span><br></pre></td></tr></table></figure>

<ol start="2">
<li>引入数据，对数据进行分集</li>
</ol>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">&#39;&#39;&#39;</span><br><span class="line">加载用于回归问题的数据集</span><br><span class="line">    :return: 一个元组，用于回归问题。元组元素依次为：训练样本集、测试样本集、训练样本集对应的值、测试样本集对应的值</span><br><span class="line">    &#39;&#39;&#39;</span><br><span class="line">    diabetes &#x3D; datasets.load_diabetes()  # 使用 scikit-learn 自带的一个糖尿病病人的数据集</span><br><span class="line">    return cross_validation.train_test_split(diabetes.data, diabetes.target,</span><br><span class="line">                                             test_size&#x3D;0.25, random_state&#x3D;0)  # 拆分成训练集和测试集，测试集大小为原始数据集大小的 1&#x2F;4</span><br></pre></td></tr></table></figure>

<ol start="3">
<li>模型预测</li>
</ol>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">&#39;&#39;&#39;</span><br><span class="line">    测试 RandomForestRegressor 的用法</span><br><span class="line">    :param data:  可变参数。它是一个元组，这里要求其元素依次为：训练样本集、测试样本集、训练样本的          值、测试样本的值</span><br><span class="line">    :return: None</span><br><span class="line">    &#39;&#39;&#39;</span><br><span class="line">    X_train, X_test, y_train, y_test &#x3D; data</span><br><span class="line">    regr &#x3D; ensemble.RandomForestRegressor()</span><br><span class="line">    regr.fit(X_train, y_train)</span><br><span class="line">    print(&quot;Traing Score:%f&quot; % regr.score(X_train, y_train))</span><br><span class="line">    print(&quot;Testing Score:%f&quot; % regr.score(X_test, y_test))</span><br></pre></td></tr></table></figure>

<p>训练集：0.89 测试集 ：0.24<br><img alt="" class="has" height="63" src="https://img-blog.csdnimg.cn/20190424175513353.png" width="254"></p>
<h3 id="自定义模型"><a href="#自定义模型" class="headerlink" title="自定义模型"></a>自定义模型</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br><span class="line">134</span><br><span class="line">135</span><br><span class="line">136</span><br><span class="line">137</span><br><span class="line">138</span><br><span class="line">139</span><br><span class="line">140</span><br><span class="line">141</span><br><span class="line">142</span><br><span class="line">143</span><br><span class="line">144</span><br><span class="line">145</span><br><span class="line">146</span><br><span class="line">147</span><br><span class="line">148</span><br><span class="line">149</span><br><span class="line">150</span><br><span class="line">151</span><br><span class="line">152</span><br><span class="line">153</span><br><span class="line">154</span><br><span class="line">155</span><br><span class="line">156</span><br><span class="line">157</span><br><span class="line">158</span><br><span class="line">159</span><br><span class="line">160</span><br><span class="line">161</span><br><span class="line">162</span><br><span class="line">163</span><br><span class="line">164</span><br><span class="line">165</span><br><span class="line">166</span><br><span class="line">167</span><br><span class="line">168</span><br><span class="line">169</span><br><span class="line">170</span><br><span class="line">171</span><br><span class="line">172</span><br><span class="line">173</span><br><span class="line">174</span><br><span class="line">175</span><br><span class="line">176</span><br><span class="line">177</span><br><span class="line">178</span><br><span class="line">179</span><br><span class="line">180</span><br><span class="line">181</span><br><span class="line">182</span><br><span class="line">183</span><br><span class="line">184</span><br><span class="line">185</span><br><span class="line">186</span><br><span class="line">187</span><br><span class="line">188</span><br><span class="line">189</span><br><span class="line">190</span><br><span class="line">191</span><br><span class="line">192</span><br><span class="line">193</span><br><span class="line">194</span><br><span class="line">195</span><br><span class="line">196</span><br><span class="line">197</span><br><span class="line">198</span><br><span class="line">199</span><br><span class="line">200</span><br><span class="line">201</span><br></pre></td><td class="code"><pre><span class="line"># -*- coding: UTF-8 -*-</span><br><span class="line">import pandas as pd</span><br><span class="line">import numpy as np</span><br><span class="line">from sklearn.ensemble import RandomForestRegressor</span><br><span class="line">from sklearn.cross_validation import train_test_split</span><br><span class="line">from sklearn.decomposition import PCA</span><br><span class="line">from sklearn import preprocessing</span><br><span class="line">from sklearn.externals import joblib</span><br><span class="line"># 各指数计算</span><br><span class="line"># PCA降维</span><br><span class="line">def pcachange(pcadata):</span><br><span class="line">    global MType</span><br><span class="line">    pcadata1 &#x3D; pcadata.fillna(0)</span><br><span class="line">    pca &#x3D; PCA(n_components&#x3D;1)</span><br><span class="line">    data_new &#x3D; pca.fit_transform(pcadata1)</span><br><span class="line">    print pcadata1.columns, pca.explained_variance_ratio_</span><br><span class="line">    joblib.dump(pca, unicode(&#39;D:&#x2F;pca&#x2F;&#39; +  str(MType) + &#39;.m&#39;, &#39;utf-8&#39;))</span><br><span class="line">    minmax_scaler &#x3D; preprocessing.MinMaxScaler(feature_range&#x3D;(0, 100))</span><br><span class="line">    joblib.dump(pca, unicode(&#39;D:&#x2F;minmax&#x2F;&#39; + str(MType) + &#39;.m&#39;, &#39;utf-8&#39;))</span><br><span class="line">    data_minmax &#x3D; minmax_scaler.fit_transform(data_new)</span><br><span class="line">    return data_minmax</span><br><span class="line"> </span><br><span class="line">#分组计算</span><br><span class="line">def cal_zs(input_features):</span><br><span class="line">    for col in input_features:</span><br><span class="line">        &#39;print(data[col])&#39;</span><br><span class="line">    data_output &#x3D; data[col]</span><br><span class="line">    data_output1 &#x3D; pcachange(data_output)</span><br><span class="line">    data_output2 &#x3D; pd.DataFrame(data_output1)</span><br><span class="line">    return data_output2</span><br><span class="line"> </span><br><span class="line">#整个预处理过程</span><br><span class="line">def preprocess(data_raw):</span><br><span class="line">    global MType</span><br><span class="line">    MType &#x3D; 0</span><br><span class="line">    info &#x3D; data_raw.iloc[:,0:12]</span><br><span class="line">    #diannei &#x3D; data_raw.iloc[:,22:89]</span><br><span class="line">    ylsale &#x3D;data_raw.iloc[:,-2]</span><br><span class="line">    sale &#x3D;data_raw.iloc[:,-1]</span><br><span class="line"> </span><br><span class="line">    ls_features &#x3D; [[&#39;t130403&#39;,&#39;t130201&#39;,&#39;t130200&#39;,&#39;t130204&#39;,&#39;t130207&#39;,&#39;t130102&#39;,&#39;t130103&#39;,&#39;t130105&#39;,&#39;t130106&#39;,&#39;t130104&#39;,&#39;t130101&#39;]]</span><br><span class="line"> </span><br><span class="line">    xzl_features &#x3D; [[&#39;t200103&#39;,&#39;t200104&#39;]]</span><br><span class="line"> </span><br><span class="line">    yl_features &#x3D; [[&#39;t180201&#39;,&#39;t180400&#39;,&#39;t180402&#39;,&#39;t180403&#39;,&#39;t180209&#39;,&#39;t180205&#39;,&#39;t180202&#39;,&#39;t180210&#39;,&#39;t180203&#39;,</span><br><span class="line">                    &#39;t180103&#39;,&#39;t180106&#39;,&#39;t180105&#39;,&#39;t180104&#39;,&#39;t180110&#39;,&#39;t180107&#39;,&#39;t180102&#39;,&#39;t180111&#39;,&#39;t180101&#39;,&#39;t180100&#39;,&#39;t120201&#39;,&#39;t120202&#39;,&#39;t120101&#39;,&#39;t120102&#39;]]</span><br><span class="line"> </span><br><span class="line">    cy_features &#x3D; [[&#39;t110101&#39;,&#39;t110102&#39;,&#39;t110103&#39;,&#39;t110200&#39;,&#39;t110301&#39;,&#39;t110303&#39;,&#39;t110302&#39;]]</span><br><span class="line"> </span><br><span class="line">    fw_features &#x3D; [[&#39;t230224&#39;,&#39;t230212&#39;,&#39;t230206&#39;,&#39;t230213&#39;,&#39;t230230&#39;,&#39;t230223&#39;,&#39;t230129&#39;,&#39;t230112&#39;,&#39;t230125&#39;,&#39;t230107&#39;,&#39;t230126&#39;,&#39;t230100&#39;,&#39;t230103&#39;,&#39;t230108&#39;]]</span><br><span class="line"> </span><br><span class="line">    jy_features &#x3D; [[ &#39;t160103&#39;, &#39;t160104&#39;, &#39;t160105&#39;]]</span><br><span class="line"> </span><br><span class="line">    jj_features &#x3D; [</span><br><span class="line">        [&#39;t800000&#39;, &#39;t800001&#39;, &#39;t800010&#39;, &#39;t800011&#39;, &#39;t800012&#39;, &#39;t800013&#39;, &#39;t800014&#39;, &#39;t800020&#39;, &#39;t800030&#39;, &#39;t800031&#39;,</span><br><span class="line">         &#39;t800032&#39;, &#39;t800035&#39;, &#39;t800036&#39;, &#39;t800037&#39;, &#39;t8_0_19&#39;, &#39;t8_0_29&#39;, &#39;t8_0_39&#39;, &#39;t8_0_49&#39;, &#39;t8_10_29&#39;, &#39;t8_10_39&#39;,</span><br><span class="line">         &#39;t8_10_49&#39;, &#39;t8_20_39&#39;, &#39;t8_20_49&#39;, &#39;t8_30_49&#39;]]</span><br><span class="line"> </span><br><span class="line">    MType &#x3D; MType + 1</span><br><span class="line">    lszs &#x3D; cal_zs(ls_features)</span><br><span class="line">    MType &#x3D; MType + 1</span><br><span class="line">    xzlzs &#x3D; cal_zs(xzl_features)</span><br><span class="line">    MType &#x3D; MType + 1</span><br><span class="line">    ylzs &#x3D; cal_zs(yl_features)</span><br><span class="line">    MType &#x3D; MType + 1</span><br><span class="line">    cyzs &#x3D; cal_zs(cy_features)</span><br><span class="line">    MType &#x3D; MType + 1</span><br><span class="line">    fwzs &#x3D; cal_zs(fw_features)</span><br><span class="line">    MType &#x3D; MType + 1</span><br><span class="line">    jyzs &#x3D; cal_zs(jy_features)</span><br><span class="line">    MType &#x3D; MType + 1</span><br><span class="line">    jjzs &#x3D; cal_zs(jj_features)</span><br><span class="line"> </span><br><span class="line">    lszs.columns &#x3D; [&#39;lszs&#39;]</span><br><span class="line">    xzlzs.columns &#x3D; [&#39;xzlzs&#39;]</span><br><span class="line">    ylzs.columns &#x3D; [&#39;ylzs&#39;]</span><br><span class="line">    cyzs.columns &#x3D; [&#39;cyzs&#39;]</span><br><span class="line">    jyzs.columns &#x3D; [&#39;jyzs&#39;]</span><br><span class="line">    jjzs.columns &#x3D; [&#39;jjzs&#39;]</span><br><span class="line">    ls &#x3D; data_raw[[&#39;t130403&#39;,&#39;t130201&#39;,&#39;t130200&#39;,&#39;t130204&#39;,&#39;t130207&#39;,&#39;t130102&#39;,&#39;t130103&#39;,&#39;t130105&#39;,&#39;t130106&#39;,&#39;t130104&#39;,&#39;t130101&#39;]]</span><br><span class="line">    cy &#x3D; data_raw[[&#39;t110101&#39;,&#39;t110102&#39;,&#39;t110103&#39;,&#39;t110200&#39;,&#39;t110301&#39;,&#39;t110303&#39;,&#39;t110302&#39;]]</span><br><span class="line">    fw &#x3D; data_raw[[&#39;t230224&#39;,&#39;t230212&#39;,&#39;t230206&#39;,&#39;t230213&#39;,&#39;t230230&#39;,&#39;t230223&#39;,&#39;t230129&#39;,&#39;t230112&#39;,&#39;t230125&#39;,&#39;t230107&#39;,&#39;t230126&#39;,&#39;t230100&#39;,&#39;t230103&#39;,&#39;t230108&#39;]]</span><br><span class="line">    yl &#x3D; data_raw[[&#39;t180201&#39;, &#39;t180400&#39;, &#39;t180402&#39;, &#39;t180403&#39;, &#39;t180209&#39;, &#39;t180205&#39;, &#39;t180202&#39;, &#39;t180210&#39;, &#39;t180203&#39;,</span><br><span class="line">                    &#39;t180103&#39;, &#39;t180106&#39;, &#39;t180105&#39;, &#39;t180104&#39;, &#39;t180110&#39;, &#39;t180107&#39;, &#39;t180102&#39;, &#39;t180111&#39;, &#39;t180101&#39;,</span><br><span class="line">                    &#39;t180100&#39;, &#39;t120201&#39;, &#39;t120202&#39;, &#39;t120101&#39;, &#39;t120102&#39;]]</span><br><span class="line">    jj &#x3D; data_raw[[&#39;t800000&#39;, &#39;t800001&#39;, &#39;t800010&#39;, &#39;t800011&#39;, &#39;t800012&#39;, &#39;t800013&#39;, &#39;t800014&#39;, &#39;t800020&#39;, &#39;t800030&#39;, &#39;t800031&#39;,</span><br><span class="line">         &#39;t800032&#39;,&#39;t800035&#39;,&#39;t800036&#39;, &#39;t800037&#39;, &#39;t8_0_19&#39;, &#39;t8_0_29&#39;, &#39;t8_0_39&#39;, &#39;t8_0_49&#39;, &#39;t8_10_29&#39;, &#39;t8_10_39&#39;,</span><br><span class="line">         &#39;t8_10_49&#39;, &#39;t8_20_39&#39;, &#39;t8_20_49&#39;, &#39;t8_30_49&#39;]]</span><br><span class="line"> </span><br><span class="line">    data_pre &#x3D; pd.concat([info,lszs,xzlzs,ylzs,jyzs,ls,cy,cyzs,fw,fwzs,jjzs,jj,yl,ylsale,sale],axis &#x3D; 1)</span><br><span class="line">    return data_pre</span><br><span class="line"> </span><br><span class="line"> </span><br><span class="line">filepath &#x3D;  u&#39;D:&#x2F;data&#x2F;f1.csv&#39;</span><br><span class="line">labelpath &#x3D; u&#39;D:&#x2F;data&#x2F;f2.csv&#39;</span><br><span class="line">data &#x3D; pd.read_csv(filepath, header&#x3D;0, sep&#x3D;&#39;,&#39;,na_values&#x3D;&#39;NULL&#39;)</span><br><span class="line">label &#x3D; pd.read_csv(labelpath, header&#x3D;0, sep&#x3D;&#39;,&#39;)</span><br><span class="line"> </span><br><span class="line"> </span><br><span class="line">data2 &#x3D; preprocess(data)</span><br><span class="line">x_labels &#x3D; data2.columns[12:-2]</span><br><span class="line">x_labels_t &#x3D; np.array(x_labels).T</span><br><span class="line">print x_labels</span><br><span class="line"> </span><br><span class="line"> </span><br><span class="line"># 销量分等级</span><br><span class="line">def cat_sale(inputdata):</span><br><span class="line">    y1 &#x3D; inputdata.iloc[:, -1]  # 销量</span><br><span class="line">    inputdata[&#39;salecat&#39;] &#x3D; pd.qcut(y1, 10, labels&#x3D;[1, 2, 3, 4, 5, 6, 7, 8, 9, 10])</span><br><span class="line">    inputdata[&#39;salecat&#39;] &#x3D; inputdata[&#39;salecat&#39;].astype(int)</span><br><span class="line">    return inputdata</span><br><span class="line"> </span><br><span class="line"> </span><br><span class="line"># 随机森林算法</span><br><span class="line">def rt_method(x_train, y_train, x_test, y_test):</span><br><span class="line">    global CityIndex,CityName</span><br><span class="line"> </span><br><span class="line">    x_train1 &#x3D; x_train.iloc[:, 12:]</span><br><span class="line">    info_train &#x3D; x_train.iloc[:, 0:12]</span><br><span class="line">    info_train1 &#x3D; info_train.reset_index(drop&#x3D;True)</span><br><span class="line">    rf0 &#x3D; RandomForestRegressor(n_estimators&#x3D;100, max_features&#x3D;&#39;sqrt&#39;,oob_score&#x3D;True)</span><br><span class="line"> </span><br><span class="line">    x_test1 &#x3D; x_test.iloc[:, 12:]</span><br><span class="line">    #rf0.fit(x_test1, y_test)</span><br><span class="line">    rf0.fit(x_train1, y_train)</span><br><span class="line">    y1 &#x3D; rf0.predict(x_train1)</span><br><span class="line">    y_train_pred &#x3D; pd.DataFrame(y1, columns&#x3D;[&#39;cat_pred&#39;])</span><br><span class="line">    y_train1 &#x3D; y_train.reset_index(drop&#x3D;True)</span><br><span class="line"> </span><br><span class="line"> </span><br><span class="line">    info_test &#x3D; x_test.iloc[:, 0:12]</span><br><span class="line">    info_test1 &#x3D; info_test.reset_index(drop&#x3D;True)</span><br><span class="line">    y2 &#x3D; rf0.predict(x_test1)</span><br><span class="line">    y_test_pred &#x3D; pd.DataFrame(y2, columns&#x3D;[&#39;cat_pred&#39;])</span><br><span class="line">    y_test1 &#x3D; y_test.reset_index(drop&#x3D;True)</span><br><span class="line"> </span><br><span class="line">    result_train &#x3D; pd.concat([info_train1, y_train_pred, y_train1], axis&#x3D;1)</span><br><span class="line">    result_train1 &#x3D; result_train.rename(columns&#x3D;&#123;&#39;salecat&#39;: &#39;cat_true&#39;&#125;)</span><br><span class="line">    result_train1[&#39;PCV&#39;] &#x3D; result_train1[&#39;cat_pred&#39;] * 10</span><br><span class="line">    result_train1.to_csv(unicode(&#39;D:&#x2F;train.csv&#39;,&#39;utf-8&#39;), index&#x3D;False, sep&#x3D;&#39;,&#39;)</span><br><span class="line"> </span><br><span class="line">    result_test &#x3D; pd.concat([info_test1, y_test_pred, y_test1], axis&#x3D;1)</span><br><span class="line">    result_test1 &#x3D; result_test.rename(columns&#x3D;&#123;&#39;salecat&#39;: &#39;cat_true&#39;&#125;)</span><br><span class="line">    result_test1[&#39;PCV&#39;] &#x3D; result_test1[&#39;cat_pred&#39;] * 10</span><br><span class="line">    result_test1.to_csv(unicode(&#39;D:&#x2F;test.csv&#39;,&#39;utf-8&#39;), index&#x3D;False, sep&#x3D;&#39;,&#39;)</span><br><span class="line"> </span><br><span class="line">    r1 &#x3D; result_train1.cat_pred.corr(result_train1.cat_true)</span><br><span class="line">    r2 &#x3D; result_test1.cat_pred.corr(result_test1.cat_true)</span><br><span class="line">    print r1, r2</span><br><span class="line"> </span><br><span class="line">    result.loc[CityIndex, [&#39;train_R&#39;]] &#x3D; r1</span><br><span class="line">    result.loc[CityIndex, [&#39;test_R&#39;]] &#x3D; r2</span><br><span class="line"> </span><br><span class="line"> </span><br><span class="line">    importances &#x3D; rf0.feature_importances_</span><br><span class="line"> </span><br><span class="line">    df_ipt &#x3D; pd.DataFrame(importances, columns&#x3D;[&quot;feature_importance&quot;])</span><br><span class="line">    feature_imp[&quot;feature_importance&quot;] &#x3D; df_ipt</span><br><span class="line">    return rf0</span><br><span class="line"> </span><br><span class="line">global CityName,CityIndex</span><br><span class="line">CityIndex &#x3D; 0</span><br><span class="line">feature_imp &#x3D; pd.DataFrame(data&#x3D;[])</span><br><span class="line">feature_imp[&#39;feature&#39;] &#x3D; x_labels_t</span><br><span class="line">result &#x3D; pd.DataFrame(data&#x3D;[], index&#x3D;[], columns&#x3D;[&#39;city&#39;, &#39;train_R&#39;, &#39;test_R&#39;, &#39;num&#39;])</span><br><span class="line">data3 &#x3D; cat_sale(data)</span><br><span class="line">X &#x3D; data3.iloc[:, 0:-2]</span><br><span class="line">Y &#x3D; data3[&#39;salecat&#39;]</span><br><span class="line">Y &#x3D; Y.fillna(1)</span><br><span class="line">X1 &#x3D; X.fillna(0)  # 用0填充空值</span><br><span class="line">X2 &#x3D; X1.replace(&#39;t&#39;, 1)  # 用1填充t值</span><br><span class="line">X_train, X_test, Y_train, Y_test &#x3D; train_test_split(X2, Y, test_size&#x3D;0.3, random_state&#x3D;42)</span><br><span class="line">rf &#x3D; rt_method(X_train, Y_train, X_test, Y_test)</span><br><span class="line">joblib.dump(rf, unicode(&#39;D:&#x2F;data&#x2F;model&#x2F;0116&#x2F;ly&#x2F;全国.m&#39;, &#39;utf-8&#39;))</span><br><span class="line"> </span><br><span class="line">&#39;&#39;&#39;for city, ctdata in data3.groupby([&#39;city_name&#39;]):</span><br><span class="line">    print city, CityIndex</span><br><span class="line">    CityName &#x3D; city</span><br><span class="line">    result.loc[CityIndex, [&#39;city&#39;]] &#x3D; city</span><br><span class="line">    n &#x3D; ctdata.iloc[:, 0].size  # 行数</span><br><span class="line">    if n &gt; 20:</span><br><span class="line">        X &#x3D; ctdata.iloc[:, 0:-2]</span><br><span class="line">        Y &#x3D; ctdata[&#39;salecat&#39;]</span><br><span class="line">        Y &#x3D; Y.fillna(1)</span><br><span class="line">        X1 &#x3D; X.fillna(0)  # 用0填充空值</span><br><span class="line">        X2 &#x3D; X1.replace(&#39;t&#39;, 1)  # 用1填充t值</span><br><span class="line">        X_train, X_test, Y_train, Y_test &#x3D; train_test_split(X2, Y, test_size&#x3D;0.3, random_state&#x3D;42)</span><br><span class="line">        try:</span><br><span class="line">            rf &#x3D; rt_method(X_train, Y_train, X_test, Y_test)</span><br><span class="line">            joblib.dump(rf, unicode(&#39;D:&#x2F;data&#x2F;model&#x2F;0115&#x2F;ly&#x2F;&#39; + str(CityName) + &#39;.m&#39;, &#39;utf-8&#39;))</span><br><span class="line">        except:</span><br><span class="line">            print (&#39;wrong&#39;)</span><br><span class="line">    else:</span><br><span class="line">        print n</span><br><span class="line">    result.loc[CityIndex, [&#39;num&#39;]] &#x3D; n</span><br><span class="line">    CityIndex &#x3D; CityIndex + 1&#39;&#39;&#39;</span><br><span class="line"> </span><br><span class="line">feature_imp1 &#x3D; pd.merge(label, feature_imp, on&#x3D;&#39;feature&#39;,how &#x3D; &#39;right&#39;)</span><br><span class="line"> </span><br><span class="line">result.to_csv(u&#39;D:&#x2F;R.csv&#39;, index&#x3D;False, sep&#x3D;&#39;,&#39;,encoding &#x3D; &#39;gbk&#39;)</span><br><span class="line">feature_imp1.to_csv(u&#39;D:&#x2F;变量重要性.csv&#39;, index&#x3D;False, sep&#x3D;&#39;,&#39;,encoding &#x3D; &#39;gbk&#39;)</span><br></pre></td></tr></table></figure>
        </div>

        <blockquote class="post-copyright">
    
    <div class="content">
        
<span class="post-time">
    最后更新时间：<time datetime="2020-04-07T06:38:59.417Z" itemprop="dateUpdated">2020-04-07 14:38:59</time>
</span><br>


        
        这里可以写作者留言，标签和 hexo 中所有变量及辅助函数等均可调用，示例：<a href="/2020/04/06/python-%E6%9C%BA%E5%99%A8%E5%AD%A6%E4%B9%A0%E4%B9%8B%E9%9A%8F%E6%9C%BA%E6%A3%AE%E6%9E%97%E7%AE%97%E6%B3%95/" target="_blank" rel="external">http://yoursite.com/2020/04/06/python-%E6%9C%BA%E5%99%A8%E5%AD%A6%E4%B9%A0%E4%B9%8B%E9%9A%8F%E6%9C%BA%E6%A3%AE%E6%9E%97%E7%AE%97%E6%B3%95/</a>
        
    </div>
    
    <footer>
        <a href="http://yoursite.com">
            <img src="/img/avatar.jpg" alt="Mr.Zhang">
            Mr.Zhang
        </a>
    </footer>
</blockquote>

        
<div class="page-reward">
    <a id="rewardBtn" href="javascript:;" class="page-reward-btn waves-effect waves-circle waves-light">赏</a>
</div>



        <div class="post-footer">
            
	<ul class="article-tag-list" itemprop="keywords"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/Python/" rel="tag">Python</a></li></ul>


            
<div class="page-share-wrap">
    

<div class="page-share" id="pageShare">
    <ul class="reset share-icons">
      <li>
        <a class="weibo share-sns" target="_blank" href="http://service.weibo.com/share/share.php?url=http://yoursite.com/2020/04/06/python-%E6%9C%BA%E5%99%A8%E5%AD%A6%E4%B9%A0%E4%B9%8B%E9%9A%8F%E6%9C%BA%E6%A3%AE%E6%9E%97%E7%AE%97%E6%B3%95/&title=《python|机器学习之随机森林算法》 — 一只咸鱼&pic=http://yoursite.com/img/avatar.jpg" data-title="微博">
          <i class="icon icon-weibo"></i>
        </a>
      </li>
      <li>
        <a class="weixin share-sns wxFab" href="javascript:;" data-title="微信">
          <i class="icon icon-weixin"></i>
        </a>
      </li>
      <li>
        <a class="qq share-sns" target="_blank" href="http://connect.qq.com/widget/shareqq/index.html?url=http://yoursite.com/2020/04/06/python-%E6%9C%BA%E5%99%A8%E5%AD%A6%E4%B9%A0%E4%B9%8B%E9%9A%8F%E6%9C%BA%E6%A3%AE%E6%9E%97%E7%AE%97%E6%B3%95/&title=《python|机器学习之随机森林算法》 — 一只咸鱼&source=分享各种福利和姿势..." data-title=" QQ">
          <i class="icon icon-qq"></i>
        </a>
      </li>
      <li>
        <a class="facebook share-sns" target="_blank" href="https://www.facebook.com/sharer/sharer.php?u=http://yoursite.com/2020/04/06/python-%E6%9C%BA%E5%99%A8%E5%AD%A6%E4%B9%A0%E4%B9%8B%E9%9A%8F%E6%9C%BA%E6%A3%AE%E6%9E%97%E7%AE%97%E6%B3%95/" data-title=" Facebook">
          <i class="icon icon-facebook"></i>
        </a>
      </li>
      <li>
        <a class="twitter share-sns" target="_blank" href="https://twitter.com/intent/tweet?text=《python|机器学习之随机森林算法》 — 一只咸鱼&url=http://yoursite.com/2020/04/06/python-%E6%9C%BA%E5%99%A8%E5%AD%A6%E4%B9%A0%E4%B9%8B%E9%9A%8F%E6%9C%BA%E6%A3%AE%E6%9E%97%E7%AE%97%E6%B3%95/&via=http://yoursite.com" data-title=" Twitter">
          <i class="icon icon-twitter"></i>
        </a>
      </li>
      <li>
        <a class="google share-sns" target="_blank" href="https://plus.google.com/share?url=http://yoursite.com/2020/04/06/python-%E6%9C%BA%E5%99%A8%E5%AD%A6%E4%B9%A0%E4%B9%8B%E9%9A%8F%E6%9C%BA%E6%A3%AE%E6%9E%97%E7%AE%97%E6%B3%95/" data-title=" Google+">
          <i class="icon icon-google-plus"></i>
        </a>
      </li>
    </ul>
 </div>



    <a href="javascript:;" id="shareFab" class="page-share-fab waves-effect waves-circle">
        <i class="icon icon-share-alt icon-lg"></i>
    </a>
</div>



        </div>
    </div>

    
<nav class="post-nav flex-row flex-justify-between">
  
    <div class="waves-block waves-effect prev">
      <a href="/2020/04/06/node-%E5%9F%BA%E4%BA%8Enode%E7%9A%84%E4%BA%91%E5%87%BD%E6%95%B0%E7%88%AC%E8%99%AB/" id="post-prev" class="post-nav-link">
        <div class="tips"><i class="icon icon-angle-left icon-lg icon-pr"></i> Prev</div>
        <h4 class="title">node|基于node的爬虫服务</h4>
      </a>
    </div>
  

  
    <div class="waves-block waves-effect next">
      <a href="/2020/04/06/mysql-%E4%B8%A4%E5%BC%A0%E8%A1%A8%E5%85%B3%E8%81%94%E5%AD%97%E6%AE%B5%E5%90%8C%E6%AD%A5%E5%AD%97%E6%AE%B5%E5%86%85%E5%AE%B9/" id="post-next" class="post-nav-link">
        <div class="tips">Next <i class="icon icon-angle-right icon-lg icon-pl"></i></div>
        <h4 class="title">mysql|关联表字段同步</h4>
      </a>
    </div>
  
</nav>



    




















</article>

<div id="reward" class="page-modal reward-lay">
    <a class="close" href="javascript:;"><i class="icon icon-close"></i></a>
    <h3 class="reward-title">
        <i class="icon icon-quote-left"></i>
        谢谢大爷~
        <i class="icon icon-quote-right"></i>
    </h3>
    <div class="reward-content">
        
        <div class="reward-code">
            <img id="rewardCode" src="/img/wechat.jpg" alt="打赏二维码">
        </div>
        
        <label class="reward-toggle">
            <input id="rewardToggle" type="checkbox" class="reward-toggle-check"
                data-wechat="/img/wechat.jpg" data-alipay="/img/alipay.jpg">
            <div class="reward-toggle-ctrol">
                <span class="reward-toggle-item wechat">微信</span>
                <span class="reward-toggle-label"></span>
                <span class="reward-toggle-item alipay">支付宝</span>
            </div>
        </label>
        
    </div>
</div>



</div>

        <footer class="footer">
    <div class="top">
        
<p>
    <span id="busuanzi_container_site_uv" style='display:none'>
        站点总访客数：<span id="busuanzi_value_site_uv"></span>
    </span>
    <span id="busuanzi_container_site_pv" style='display:none'>
        站点总访问量：<span id="busuanzi_value_site_pv"></span>
    </span>
</p>


        <p>
            
                <span><a href="/atom.xml" target="_blank" class="rss" title="rss"><i class="icon icon-lg icon-rss"></i></a></span>
            
            <span>博客内容遵循 <a rel="license noopener" href="https://creativecommons.org/licenses/by-nc-sa/4.0/deed.zh" target="_blank">知识共享 署名 - 非商业性 - 相同方式共享 4.0 国际协议</a></span>
        </p>
    </div>
    <div class="bottom">
        <p><span>Mr.Zhang &copy; 2015 - 2020</span>
            <span>
                
                Power by <a href="http://hexo.io/" target="_blank">Hexo</a> Theme <a href="https://github.com/yscoder/hexo-theme-indigo" target="_blank">indigo</a>
            </span>
        </p>
    </div>
</footer>

    </main>
    <div class="mask" id="mask"></div>
<a href="javascript:;" id="gotop" class="waves-effect waves-circle waves-light"><span class="icon icon-lg icon-chevron-up"></span></a>



<div class="global-share" id="globalShare">
    <ul class="reset share-icons">
      <li>
        <a class="weibo share-sns" target="_blank" href="http://service.weibo.com/share/share.php?url=http://yoursite.com/2020/04/06/python-%E6%9C%BA%E5%99%A8%E5%AD%A6%E4%B9%A0%E4%B9%8B%E9%9A%8F%E6%9C%BA%E6%A3%AE%E6%9E%97%E7%AE%97%E6%B3%95/&title=《python|机器学习之随机森林算法》 — 一只咸鱼&pic=http://yoursite.com/img/avatar.jpg" data-title="微博">
          <i class="icon icon-weibo"></i>
        </a>
      </li>
      <li>
        <a class="weixin share-sns wxFab" href="javascript:;" data-title="微信">
          <i class="icon icon-weixin"></i>
        </a>
      </li>
      <li>
        <a class="qq share-sns" target="_blank" href="http://connect.qq.com/widget/shareqq/index.html?url=http://yoursite.com/2020/04/06/python-%E6%9C%BA%E5%99%A8%E5%AD%A6%E4%B9%A0%E4%B9%8B%E9%9A%8F%E6%9C%BA%E6%A3%AE%E6%9E%97%E7%AE%97%E6%B3%95/&title=《python|机器学习之随机森林算法》 — 一只咸鱼&source=分享各种福利和姿势..." data-title=" QQ">
          <i class="icon icon-qq"></i>
        </a>
      </li>
      <li>
        <a class="facebook share-sns" target="_blank" href="https://www.facebook.com/sharer/sharer.php?u=http://yoursite.com/2020/04/06/python-%E6%9C%BA%E5%99%A8%E5%AD%A6%E4%B9%A0%E4%B9%8B%E9%9A%8F%E6%9C%BA%E6%A3%AE%E6%9E%97%E7%AE%97%E6%B3%95/" data-title=" Facebook">
          <i class="icon icon-facebook"></i>
        </a>
      </li>
      <li>
        <a class="twitter share-sns" target="_blank" href="https://twitter.com/intent/tweet?text=《python|机器学习之随机森林算法》 — 一只咸鱼&url=http://yoursite.com/2020/04/06/python-%E6%9C%BA%E5%99%A8%E5%AD%A6%E4%B9%A0%E4%B9%8B%E9%9A%8F%E6%9C%BA%E6%A3%AE%E6%9E%97%E7%AE%97%E6%B3%95/&via=http://yoursite.com" data-title=" Twitter">
          <i class="icon icon-twitter"></i>
        </a>
      </li>
      <li>
        <a class="google share-sns" target="_blank" href="https://plus.google.com/share?url=http://yoursite.com/2020/04/06/python-%E6%9C%BA%E5%99%A8%E5%AD%A6%E4%B9%A0%E4%B9%8B%E9%9A%8F%E6%9C%BA%E6%A3%AE%E6%9E%97%E7%AE%97%E6%B3%95/" data-title=" Google+">
          <i class="icon icon-google-plus"></i>
        </a>
      </li>
    </ul>
 </div>


<div class="page-modal wx-share" id="wxShare">
    <a class="close" href="javascript:;"><i class="icon icon-close"></i></a>
    <p>扫一扫，分享到微信</p>
    <img src="//api.qrserver.com/v1/create-qr-code/?data=http://yoursite.com/2020/04/06/python-%E6%9C%BA%E5%99%A8%E5%AD%A6%E4%B9%A0%E4%B9%8B%E9%9A%8F%E6%9C%BA%E6%A3%AE%E6%9E%97%E7%AE%97%E6%B3%95/" alt="微信分享二维码">
</div>




    <script src="//cdn.bootcss.com/node-waves/0.7.4/waves.min.js"></script>
<script>
var BLOG = { ROOT: '/', SHARE: true, REWARD: true };


</script>

<script src="//unpkg.com/hexo-theme-material-indigo@latest/js/main.min.js"></script>


<div class="search-panel" id="search-panel">
    <ul class="search-result" id="search-result"></ul>
</div>
<template id="search-tpl">
<li class="item">
    <a href="{path}" class="waves-block waves-effect">
        <div class="title ellipsis" title="{title}">{title}</div>
        <div class="flex-row flex-middle">
            <div class="tags ellipsis">
                {tags}
            </div>
            <time class="flex-col time">{date}</time>
        </div>
    </a>
</li>
</template>

<script src="//unpkg.com/hexo-theme-material-indigo@latest/js/search.min.js" async></script>






<script async src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>



<script>
(function() {
    var OriginTitile = document.title, titleTime;
    document.addEventListener('visibilitychange', function() {
        if (document.hidden) {
            document.title = '死鬼去哪里了！';
            clearTimeout(titleTime);
        } else {
            document.title = '(つェ⊂)咦!又好了!';
            titleTime = setTimeout(function() {
                document.title = OriginTitile;
            },2000);
        }
    });
})();
</script>



</body>
</html>
